import 'package:flutter/material.dart';
import 'package:sports_new/utils/utils.dart';
import 'package:sports_new/widgets/base/qkd_text.dart';

enum AssetDirection{
  ltr(Axis.horizontal,false),
  rtl(Axis.horizontal,true),
  ttb(Axis.vertical,false),
  btt(Axis.vertical,true);

  final Axis axis;
  final bool needReverse;

  const AssetDirection(this.axis,this.needReverse);

}

class AssetItem extends StatelessWidget {
  const AssetItem({super.key,
    required this.asset,
    this.name,
    required this.assetSize,
    this.onTap,
    this.textStyle,
    this.space = 4,
    this.direction = AssetDirection.ttb,
    this.padding
  });

  final String asset;
  final double assetSize;
  final String? name;
  final TextStyle? textStyle;
  final double space;
  final AssetDirection direction;
  final EdgeInsets? padding;
  final Function()? onTap;

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [
      Image.asset(Utils.getImgPath(asset),width: assetSize,height: assetSize),
      SizedBox(
          width: direction.axis == Axis.horizontal?space:0,
          height: direction.axis == Axis.vertical?space:0
      ),
      if(name.hasValue??false)
      QkdText.style(name,style: textStyle)
    ];
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: Padding(
        padding: padding??EdgeInsets.zero,
        child: Flex(
          mainAxisSize: MainAxisSize.min,
          direction: direction.axis,
          children: (direction.needReverse??false)? list.reversed.toList(): list
        ),
      ),
    );
  }
}
